package Presentation;

import java.awt.Color;
import java.awt.Font;
import java.util.Vector;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

import Logic.Rank;
import Logic.User;

public class RanksPanel extends JPanel{
		
	public RanksPanel(final MainFrame main, Vector<Rank> ranks, String header, int byWho){
		super();		
		setLayout(null);
		setSize(350,400);
		setBorder(new LineBorder(Color.black));
		
		JLabel headerL = new MyLabel(header,300,50,25,10);
		headerL.setHorizontalAlignment(SwingConstants.CENTER);
		headerL.setVerticalAlignment(SwingConstants.CENTER);
		headerL.setFont(new Font("Arial",Font.BOLD,20));		
		add(headerL);
		
		int size = ranks.size();
		String[][] ranksArray = new String[size][2];
		String[] headers = new String[2];
		JTable ranksT;
		
		if (byWho == 1){
			headers[0] = "Movie";
			headers[1] = "Rank";
			for (int i=0; i<size; i++){
				ranksArray[i][0] = ranks.get(i).getMovie().toString();
				ranksArray[i][1] = ranks.get(i).getRank() + "";
			}			
		}
		else if (byWho == 2){
			headers[0] = "User";
			headers[1] = "Rank";
			for (int i=0; i<size; i++){
				ranksArray[i][0] = ranks.get(i).getUser().toString();
				ranksArray[i][1] = ranks.get(i).getRank() + "";
			}			
		}
		ranksT = new JTable(ranksArray,headers);
		
		ranksT.setSize(300, 300);		
		ranksT.setLocation(0, 0);
		
		ranksT.getColumnModel().getColumn(0).setPreferredWidth(300);
		ranksT.getColumnModel().getColumn(1).setPreferredWidth(50);

		JScrollPane scrollPane = new JScrollPane(ranksT);
		ranksT.setFillsViewportHeight(true);
		scrollPane.setSize(300, 300);		
		scrollPane.setLocation(25, 70);
		scrollPane.setBorder(new LineBorder(Color.black));
		add(scrollPane);
	
				
		//JScrollPane scrollPane = new JScrollPane(dataList);
		 // Or in two steps:
		// JScrollPane scrollPane = new JScrollPane();
		// scrollPane.getViewport().setView(dataList);
	}
}
